﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace haptic.src.engine.core
{
    public class Result
    {
        #region Constructors
        public Result()
        {
            m_bError = true;
            Log.Error(m_sMsg);
        }
        public Result(string sMsg)
        {
            m_sMsg = sMsg;
            m_bError = true;
            Log.Error(m_sMsg);
        }
        public Result(string sMsg, bool bLog)
        {
            m_sMsg = sMsg;
            m_bError = true;
            Log.Error(m_sMsg);
        }
        public Result(bool bLog)
        {
            m_bError = true;
            Log.Error(m_sMsg);
        }
        public Result(int iVal, bool bError, string sMsg)
        {
            m_iValue = iVal;
            m_bError = bError;
            m_sMsg = sMsg;
            if (m_bError)
                Log.Error(m_sMsg);
        }
        #endregion

        public override bool Equals(object o)
        {
            if (o.GetType() == typeof(Result))
            {
                Result oRes2 = (Result)o;
                if (!m_bError && !oRes2.m_bError)
                    return true;
                if (m_bError == oRes2.m_bError && m_iValue == oRes2.m_iValue)
                    return true;
            }
            return false;
        }

        public bool IsSuccess()
        {
            return !m_bError;
        }
        public bool IsFailed()
        {
            return m_bError;
        }

        #region Constants
        public static Result Success = new Result(0, false, null);
        #endregion

        #region Attributes
        protected int m_iValue = 1;
        protected bool m_bError = false;
        protected string m_sMsg;
        #endregion
    }

    public class Failed : Result
    {
        #region Constructors
        public Failed()
        {
            m_bError = true;
        }
        public Failed(string sMsg)
        {
            m_sMsg = sMsg;
            m_bError = true;
        }
        public Failed(string sMsg, bool bLog)
        {
            m_sMsg = sMsg;
            m_bError = true;
        }
        public Failed(bool bLog)
        {
            m_bError = true;
        }
        #endregion
    }
}